function createManagerPanel() {
	
	var dataStore = Ext.create('Ext.data.Store', {
	    storeId:'mngStore',
	    fields:['id', 'account', 'pwd', 'power' ],
	    data:{'items':[
	       	        { "id": 1, "account":"Lisa", 'pwd':'******', "power":"超级管理员"},
	       	        { "id": 2, "account":"Bart", 'pwd':'******', "power":"管理员" },
	       	        { "id": 3, "account":"Homer", 'pwd':'******', "power":"管理员" },                        
	       	        { "id": 4, "account":"Marge", 'pwd':'******', "power":"管理员" }            
	       	    ]},
	    proxy: {
	        type: 'memory',
	        reader: {
	            type: 'json',
	            root: 'items'
	        }
	    }
	});
	
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });


	var ManagerPanel = Ext.create('Ext.panel.Panel', {
		title : '管理员帐号管理',
		
		id: 'manager-panel',
		
		iconCls: 'panel-title',
		
		layout: 'fit',
		
		tbar : Ext.create('Ext.toolbar.Toolbar', {
			items : [ {
				xtype : 'button',
				text : '添加',
				iconCls: 'icon-add',
				handler: function() {
					Ext.create('Ext.window.Window', {
						id: 'mngPanelAddWindow',
						title: '添加管理员帐号', 
						width: 300,
						height: 200,
						bodyPadding: '20,0,20, 30',
						modal: true,
						items: [{
							xtype: 'textfield',
					        fieldLabel: '管理员帐号',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						},{
							xtype: 'textfield',
					        fieldLabel: '密码',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						},{
							xtype: 'textfield',
					        fieldLabel: '确认密码',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						}],
						buttons: [{
							text: '确 定',
							handler: function() {
								alert();
							}
						}, {
							text: '取 消',
							handler: function() {
								Ext.getCmp('mngPanelAddWindow').close();
							}
						}]
					}).show();
				}
			}, {
				xtype : 'tbseparator'
			}, {
				id: 'mngp-removeButton',
				xtype : 'button',
				text : '删除',
				iconCls: 'icon-delete',
				disabled: true,
				handler: function() {
					Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
				}
			} ]
		}),
		
		items: [Ext.create('Ext.grid.Panel', {
			id: 'managerPanelGrid',
		    store: dataStore,
		    selModel: Ext.create('Ext.selection.CheckboxModel', {
		    	listeners: {
		            selectionchange: function(sm, selections) {
		                Ext.getCmp('mngp-removeButton').setDisabled(selections.length == 0);
		            }
		        }
		    }),
		    columns: [
		        { header: 'ID',  dataIndex: 'id', width: 80 },
		        { header: '帐号',  dataIndex: 'account', width: 200},
		        { header: '密码',  dataIndex: 'pwd', width: 200},
		        { header: '权限', dataIndex: 'power' },
		        {
		        	header: '操作',
		        	xtype:'actioncolumn', 
		        	width: 70,
		        	items: [{
		                icon: 'img/edit.png',
		                iconCls: 'cursor-pointer',
		                toolTip: '修改密码',
		                handler: function(grid, rowIndex, colIndex) {
		                	var rec = grid.getStore().getAt(rowIndex);
		                    alert(rec.get('account'));
		                }
		            }]
		        }
		    ]
		})]
	});
	
	return ManagerPanel;
}

function createUserPanel() {
	var dataStore = Ext.create('Ext.data.Store', {
	    storeId:'userStore',
	    fields:['id', 'account', 'pwd', 'power', 'university', 'email'],
	    data:{'items':[
	        { "id": 1, "account":"117292775", 'pwd':'******', "power":"普通用户", 'university':'华南农业大学', 'email':'117292775@qq.com'},
	        { "id": 2, "account":"117292775", 'pwd':'******', "power":"普通用户", 'university':'华南农业大学', 'email':'117292775@qq.com'}
	    ]},
	    proxy: {
	        type: 'memory',
	        reader: {
	            type: 'json',
	            root: 'items'
	        }
	    }
	});
	
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });
	
	var UserPanel = Ext.create('Ext.panel.Panel', {
		id: 'user-panel',

		title : '普通用户管理',
		
		iconCls: 'panel-title',

		layout: 'fit',
		
		
		tbar : Ext.create('Ext.toolbar.Toolbar', {
			items : [ {
				xtype : 'button',
				text : '添加',
				iconCls: 'icon-add',
				disabled: true,
				handler: function() {
					Ext.create('Ext.window.Window', {
						id: 'userPanelAddWindow',
						title: '添加管理员帐号', 
						width: 300,
						height: 200,
						bodyPadding: '20,0,20, 30',
						modal: true,
						items: [{
							xtype: 'textfield',
					        fieldLabel: '管理员帐号',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						},{
							xtype: 'textfield',
					        fieldLabel: '密码',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						},{
							xtype: 'textfield',
					        fieldLabel: '确认密码',
					        labelWidth: 70,
					        allowBlank: false,
					        margin: '0 0 10 0'
						}],
						buttons: [{
							text: '确 定',
							handler: function() {
								alert();
							}
						}, {
							text: '取 消',
							handler: function() {
								Ext.getCmp('userPanelAddWindow').close();
							}
						}]
					}).show();
				}
			}, {
				xtype : 'tbseparator'
			}, {
				id: 'userp-removeButton',
				xtype : 'button',
				text : '删除',
				iconCls: 'icon-delete',
				disabled: true,
				handler: function() {
					Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
				}
			} ]
		}),
		
		
		items: [Ext.create('Ext.grid.Panel', {
			id: 'userPanelGrid',
		    store: dataStore,
		    selModel: Ext.create('Ext.selection.CheckboxModel', {
		    	listeners: {
		            selectionchange: function(sm, selections) {
		                Ext.getCmp('userp-removeButton').setDisabled(selections.length == 0);
		            }
		        }
		    }),
			plugins: [rowEditing],
			columnLines: true,
		    columns: [
		         Ext.create('Ext.grid.RowNumberer'),
		        { header: 'ID',  dataIndex: 'id', width: 80 },
		        { header: '帐号',  dataIndex: 'account', width: 180, field: 'textfield'},
		        { header: '密码',  dataIndex: 'pwd', width: 180, field: 'textfield'},
		        { header: '权限', dataIndex: 'power', width: 80 },
		        { header: '所在大学', dataIndex: 'university', width: 150, field: 'textfield'},
		        { header: 'E-mail', dataIndex: 'email', field: 'textfield' },
		        {
		        	header: '操作',
		        	xtype:'actioncolumn', 
		        	width: 70,
		        	items: [{
		                icon: 'img/edit.png',
		                iconCls: 'cursor-pointer',
		                toolTip: '修改密码',
		                handler: function(grid, rowIndex, colIndex) {
		                    rowEditing.cancelEdit();
		                    rowEditing.startEdit(rowIndex, 0);
		                }
		            }]
		        }
		    ]
		})]
	});
	
	return UserPanel;
}

/*
Ext.define("University.AddWindow", {
	extend: 'Ext.window.Window',
	alias: 'widget.universityaddwindow',
	
	requires: [],
	
	initComponent: function() {
		Ext.apply(this, {
			title : '管理员帐号管理',
			title: '添加校区', 
			width: 320,
			height: 130,
			modal: true,
			layout: "fit",
			items: [{
				xtype: "form",
				bodyPadding: '20,0,20, 30',
				url: 'university/add',
				method: "post",
				items: [{
					xtype: 'textfield',
					id: "universityField",
			        fieldLabel: '校区名称',
			        labelWidth: 60,
			        allowBlank: false,
			        name: "university.name",
			        margin: '0 0 10 0',
			        msgTarget: 'side',
			        width: 230
				}],
				buttons: [{
					text: '确 定 ',
					formBind: true, 
		            disabled: true,
		            handler: function() {
						var window = this.up("window");
						window.onSubmitForm(this.up("form").getForm(), window);
						
		            }
				},{
					text: '取 消',
					handler: function() {
						this.up("window").close();
					}
				}]
			}]
		});
		this.callParent();
	},
	
	onSubmitForm: function(form, window) {
		if(form.isValid()) {
			form.submit({
            	waitMsg: "正在添加...",
            	onSureClick : function(form) {
            		var rec = Ext.create("Writer.University", {
            			name: form.findField("universityField").getSubmitValue()
            		});
            		var dataStore = Ext.data.StoreManager.lookup("universityStore");
            		dataStore.add(rec);
            		window.close();
            		return true;
            	},
                success: function(form, action) {
                	if(action.result.success && action.result.success == "true") {
                		this.onSureClick(form);
            		} else {
            			this.failure(form, action);
            		}
                },
                failure: function(form, action) {
                	if(action.result.success && action.result.success == "true") {
                		this.onSureClick(form);
                	}
                	if(action.result.serverErrMsg) {
                		Ext.Msg.alert("Server Error!", action.result.serverErrMsg);
                		return;
                	}
                	if(action.result.universityErrMsg) {
                		form.findField("universityField").markInvalid(action.result.universityErrMsg);
                	}
                }
            });
		}
	}
	
});
*/
function createUniversityPanel() {
	Ext.define('University', {
	    extend: 'Ext.data.Model',
	    fields:['id', 'name']
	});
	
	var dataStore = Ext.create('Ext.data.Store', {
	    storeId:'universityStore',
	    model: "University",
	    autoSync: true,
	    proxy: {
	        type: 'ajax',
	        api: {
				read: 'university/list',
				update: 'university/update'
			},
			reader: {
                type: 'json'
            },
			writer: {
                type: 'json',
                writeAllFields: false,
                root: 'university'
            }
	    }
	});
	
	dataStore.load();
	
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });
	
	Ext.define('Writer.University', {
	    extend: 'Ext.data.Model',
	    fields: [{
	        name: 'name',
	        type: 'int'
	    }],
	    validations: [{
	        type: 'length',
	        field: 'name',
	        min: 1
	    }]
	});
	
	
	var UniversityPanel = Ext.create('Ext.panel.Panel', {
		id: 'university-panel',

		title : '校区管理',
		
		iconCls: 'panel-title',

		layout: 'fit',
		
		
		tbar : Ext.create('Ext.toolbar.Toolbar', {
			items : [ {
				xtype : 'button',
				text : '添加',
				iconCls: 'icon-add',
				handler: function() {
					var addWindow = Ext.create('Ext.window.Window', {
						id: 'unvPanelAddWindow',
						title: '添加校区', 
						width: 320,
						height: 180,
						modal: true,
						layout: "fit",
						items: [{
							xtype: "form",
							bodyPadding: '20,0,20, 30',
							url: 'university/add',
	        				method: "post",
							items: [{
								xtype: 'textfield',
								id: "universityField",
						        fieldLabel: '校区名称',
						        labelWidth: 85,
						        allowBlank: false,
						        name: "university.name",
						        margin: '0 0 10 0',
						        msgTarget: 'side'
							}],
							buttons: [{
								text: '确 定 ',
								formBind: true, 
					            disabled: true,
					            handler: function() {
					                var form = this.up('form').getForm();
					                if (form.isValid()) {
					                    form.submit({
					                    	waitMsg: "正在添加...",
					                    	onSureClick : function(form) {
					                    		addWindow.close();
					                    		var rec = Ext.create("Writer.University", {
					                    			name: form.findField("universityField").getValue()
					                    		});
					                    		dataStore.add(dataStore.getTotalCount(), rec);
					                    		dataStore.sync();
					                    	},
					                        success: function(form, action) {
					                        	if(action.result.success && action.result.success == "true") {
					                        		this.onSureClick(form);
					                    		} else {
					                    			this.failure(form, action);
					                    		}
					                        },
					                        failure: function(form, action) {
					                        	if(action.result.success && action.result.success == "true") {
					                        		this.onSureClick(form);
					                        	}
					                        	if(action.result.serverErrMsg) {
					                        		Ext.Msg.alert("Server Error!", action.result.serverErrMsg);
					                        		return;
					                        	}
					                        	if(action.result.universityErrMsg) {
					                        		form.findField("universityField").markInvalid(action.result.universityErrMsg);
					                        	}
					                        }
					                    });
					                }
								}
							}, {
								text: '取 消',
								handler: function() {
									Ext.getCmp('unvPanelAddWindow').close();
								}
							}]
						}]
					});
					addWindow.show();
				}
			}, {
				xtype : 'tbseparator'
			}, {
				id: 'unvp-removeButton',
				xtype : 'button',
				text : '删除',
				iconCls: 'icon-delete',
				disabled: true,
				handler: function() {
					Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
				}
			} ]
		}),
		
		
		items: [Ext.create('Ext.grid.Panel', {
			id: 'unvPanelGrid',
		    store: dataStore,
		    selModel: Ext.create('Ext.selection.CheckboxModel', {
		    	listeners: {
		            selectionchange: function(sm, selections) {
		                Ext.getCmp('unvp-removeButton').setDisabled(selections.length == 0);
		            }
		        }
		    }),
			plugins: [rowEditing],
			columnLines: true,
		    columns: [
		         Ext.create('Ext.grid.RowNumberer'),
		        { header: '大学名称', dataIndex: 'name', width: 150, field: 'textfield'},
		        
		        {
		        	header: '操作',
		        	xtype:'actioncolumn', 
		        	width: 70,
		        	items: [{
		                icon: 'img/edit.png',
		                iconCls: 'cursor-pointer',
		                toolTip: '修改密码',
		                handler: function(grid, rowIndex, colIndex) {
		                    rowEditing.cancelEdit();
		                    rowEditing.startEdit(rowIndex, 0);
		                }
		            }]
		        }
		    ]
		})]
	});
	
	return UniversityPanel;
}